// Copyright (C) 2025, ZWSOFT Co., LTD.(Guangzhou)
// Licensed under the MIT License. See LICENSE in the project root for license information.

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using TestClient.Domain;

namespace TestClient.ViewModel;
public partial class OffsetTestViewModel : PageViewModelBase
{
    [ObservableProperty]
    private string surfaceId = "";
    [ObservableProperty]
    private double offset;

    [ObservableProperty]
    private string resultSurface = "";

    public IAsyncRelayCommand SelectSurfaceCommand { get; }
    public IAsyncRelayCommand OffsetSurfaceCommand { get; }


    public OffsetTestViewModel(VFAdapterWrapper wrapper, ISnackNotifyService notifyService) : base(wrapper, notifyService)
    {
        SelectSurfaceCommand = CreateAsyncRpcCommand(SelectSurface);
        OffsetSurfaceCommand = CreateAsyncRpcCommand(OffsetSurface);
    }

    private async Task SelectSurface()
    {
        EnsureConnected();
        SurfaceId = await ViewModelHelpers.SelectEnt(Wrapper, "Surface");
    }

    private async Task OffsetSurface()
    {
        EnsureConnected();
        ResultSurface = await Task.Run(() =>
        {
            return Wrapper.OffsetSurface(SurfaceId, Offset);
        });
    }
}
